package leo.game.ui
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import leo.data.TowerVO;
	import leo.manager.McMannager;

	/**
	 * 提示类 
	 * @author leo
	 * 
	 */	
	public class UITooltip extends Sprite
	{
		private static var _instance :UITooltip = null;
		
		private var tooltip :MovieClip;
		private var txtTooltip :TextField;
		public function UITooltip()
		{
			super();
			
			var name :String = "Tooltip";
			this.tooltip = McMannager.instance.getMCByName(name);
			this.addChild(this.tooltip);
			this.txtTooltip = this.tooltip.txtTooltip;
		}
		/**
		 * 顯示tootip 
		 * @param tx
		 * @param ty
		 * @param towerVO
		 * @param str
		 * 
		 */		
		public function showTooltip(tx :Number,ty :Number,towerVO :TowerVO,str :String = null):void
		{
			if(UIMap.instance.dragTower) return;
			if(!this.visible) this.visible = true;

			if(towerVO)
			{
				this.x = tx;
				this.y = ty - 75;
				this.txtTooltip.multiline = true;
				this.txtTooltip.autoSize = TextFieldAutoSize.LEFT;
				this.tooltip.bg_mc.rect_mc.width = 100;
				this.tooltip.bg_mc.rect_mc.height = 100;
				this.tooltip.bg_mc.arrow.x = this.tooltip.bg_mc.x + 100;
				this.tooltip.bg_mc.arrow.y = this.tooltip.bg_mc.y + 145;
				this.txtTooltip.text = towerVO.name +"\n" 
					                   + "攻击力：" + towerVO.attack + "\n"
									   + "攻击速度：" + towerVO.attSpeed/1000 + "\n"
				                       + "攻击范围：" + towerVO.attRange + "\n"
									   + "价格：" + towerVO.price + "\n"
				                       + towerVO.describe;
			}else
			{
				this.txtTooltip.text = str;
				this.x = tx + 30;
				this.y = ty - 20;
				this.txtTooltip.multiline = false;
				this.txtTooltip.autoSize = TextFieldAutoSize.CENTER;
				this.tooltip.bg_mc.rect_mc.width = 60;
				this.tooltip.bg_mc.rect_mc.height = 30;
				this.tooltip.bg_mc.arrow.x = this.tooltip.bg_mc.x + 80;
				this.tooltip.bg_mc.arrow.y = this.tooltip.bg_mc.y + 75;
			}
		}
		/**
		 * 隐藏tooltip 
		 * 
		 */		
		public function hideTooltip():void
		{
			this.visible = false;
		}
		
		public function checkIsMouseOn():void
		{
			var rect :Rectangle = getBounds(this.tooltip.bg_mc.rect_mc);
			if(rect.contains(this.stage.mouseX,this.stage.mouseY))
			{
				this.visible = false;
			}
		}

		public static function get instance():UITooltip
		{
			if(_instance == null)
			{
				_instance = new UITooltip();
			}
			return _instance;
		}

	}
}